package com.example.myapplication;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.example.myapplication.gridview.GridViewActivity;
import com.example.myapplication.listview.ListViewActivity;

public class MainActivity extends AppCompatActivity {

    private Button mBunTextView;
    private Button mBunButton;
    private Button mBunEditText;
    private Button mBunRadioButton;
    private Button mBunCheckBox;
    private Button mBunImageView;
    private Button mBunListView;
    private Button mBunGridView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mBunTextView = findViewById(R.id.btn_textview);
        mBunButton = findViewById(R.id.btn_button);
        mBunEditText = findViewById(R.id.btn_edittext);
        mBunRadioButton = findViewById(R.id.btn_radiobutton);
        mBunCheckBox = findViewById(R.id.btn_checkbox);
        mBunImageView = findViewById(R.id.btn_imageview);
        mBunListView = findViewById(R.id.btn_listview);
        mBunGridView = findViewById(R.id.btn_gridview);
        setListeners();
    }

    private void setListeners(){
        OnClick onClick = new OnClick();
        mBunTextView.setOnClickListener(onClick);
        mBunButton.setOnClickListener(onClick);
        mBunEditText.setOnClickListener(onClick);
        mBunRadioButton.setOnClickListener(onClick);
        mBunCheckBox.setOnClickListener(onClick);
        mBunImageView.setOnClickListener(onClick);
        mBunListView.setOnClickListener(onClick);
        mBunGridView.setOnClickListener(onClick);
    }

    private class OnClick implements View.OnClickListener{

        @Override
        public void onClick(View v) {
            Intent intent = null;
            switch (v.getId()){
                case R.id.btn_textview:
                    intent = new Intent(MainActivity.this, TextViewActivity.class);
                    break;
                case R.id.btn_button:
                    intent = new Intent(MainActivity.this,ButtonActivity.class);
                    break;
                case R.id.btn_edittext:
                    intent = new Intent(MainActivity.this,EditTextActivity.class);
                    break;
                case R.id.btn_radiobutton:
                    intent = new Intent(MainActivity.this,RadioButtonActivity.class);
                    break;
                case R.id.btn_checkbox:
                    intent = new Intent(MainActivity.this, CheckBoxActivity.class);
                    break;
                case R.id.btn_imageview:
                    intent = new Intent(MainActivity.this,ImageViewActivity.class);
                    break;
                case  R.id.btn_listview:
                    intent = new Intent(MainActivity.this, ListViewActivity.class);
                    break;
                case R.id.btn_gridview:
                    intent = new Intent(MainActivity.this, GridViewActivity.class);
                    break;
            }
            startActivity(intent);
        }
    }
}
